﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.gameState.intro;
using imaginecup.util;
using Microsoft.Xna.Framework;
using Imaginecup.sprite;
using Imaginecup.scroll;
using Microsoft.Xna.Framework.Graphics;
using Imaginecup.gameState.ending.unuse;

namespace Imaginecup.gameState.ending.scene5.unuse
{
    public class EndingScene5_3
    {
        private SimpleDrawObject[] m_SimpleObject = new SimpleDrawObject[m_MaxCount];
        private ScrollMan[] m_ScrollMan = new ScrollMan[m_MaxCount];
        private const int m_MaxCount = 3;

        public EndingScene5_3(int initY)
        {
            EntityInfo info = new EntityInfo();
            int objectOffset = 70;          

            info.mPosition.X = 0;
            info.mPosition.Y = initY + 50;
            info.mSize = new Vector2(390, 84);

            m_SimpleObject[0] = new SimpleDrawObject();
            m_SimpleObject[0].SetEntityInfo(info);

            m_ScrollMan[0] = new ScrollMan();
            m_ScrollMan[0].SetScrollProcess(new WidthLeftScroll(info.mSize.X + objectOffset, 160));
            m_ScrollMan[0].StopScroll();

            objectOffset += 70;
            info.mPosition.Y += 60;
            info.mSize = new Vector2(460, 105);
            m_SimpleObject[1] = new SimpleDrawObject();
            m_SimpleObject[1].SetEntityInfo(info);

            m_ScrollMan[1] = new ScrollMan();
            m_ScrollMan[1].SetScrollProcess(new WidthLeftScroll(info.mSize.X + objectOffset, 120));
            m_ScrollMan[1].StopScroll();


            objectOffset = 365;
            info.mPosition.X = 800 + objectOffset;
            info.mPosition.Y += 65;
            info.mSize = new Vector2(428, 185);
            m_SimpleObject[2] = new SimpleDrawObject();
            m_SimpleObject[2].SetEntityInfo(info);

            m_ScrollMan[2] = new ScrollMan();
            m_ScrollMan[2].SetScrollProcess(new WidthRightScroll(0, 150, 800));
            m_ScrollMan[2].StopScroll();
        }



        public void LoadEndingScene()
        {
            for (int i = 0; i < m_MaxCount; i++)
            {
                NormalSprite sprite = new NormalSprite();
                sprite.SetTextureName("" + (i + 10));
                m_SimpleObject[i].SetSprite(sprite);
            }

        }

        public void UnloadEndingScene()
        {
            for (int i = 0; i < m_MaxCount; i++)
                m_SimpleObject[i].Release();
            m_SimpleObject = null;
            m_ScrollMan = null;
        }


        public void StartAnimation()
        {
            for (int i = 0; i < m_MaxCount; i++)
                m_ScrollMan[i].StartScroll();
        }

        public void Update(GameTime gameTime , ScrollMan scrollMan)
        {
            for (int i = 0; i < m_MaxCount; i++)
            {
                m_SimpleObject[i].SubPositionToInit(new Vector2(m_ScrollMan[i].GetCurrentStartPos().X, scrollMan.GetCurrentStartPos().Y));
            }

            for (int i = 0; i < m_MaxCount; i++)
                m_ScrollMan[i].Update(gameTime);
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            for (int i = m_MaxCount - 1; i >= 0; i--)
            {
                m_SimpleObject[i].Draw(spriteBatch);
            }

        }
    }
}
